home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-26 | 2.8 KB | 96 lines | [TEXT/R*ch] |
- Hey, Finder, Pay Attention!
- I have run into several things which change a file’s creator but the
- Finder doesn’t update the file’s icon right away. The user often has
- to close and reopen the Finder window to get the proper icons to
- appear. If your application needs to fiddle with a file’s creator type
- or other attributes, you can solve the above problem by changing the
- ioDrMdDat field of your file’s parent directory. This “tricks” the
- Finder into updating the window.
-
- void ForceFinderToUpdateFileIcon(
- FSSpecPtr theFile)
- {
- CInfoPBRec tempPB;
-
- if(theFile != 0L)
- {
- tempPB.dirInfo.ioNamePtr = 0L;
- tempPB.dirInfo.ioVRefNum=theFile->vRefNum;
- tempPB.dirInfo.ioFDirIndex = -1;
- tempPB.dirInfo.ioDrDirID = theFile->parID;
-
- if(PBGetCatInfoSync(&tempPB) == noErr)
- {
- tempPB.dirInfo.ioDrMdDat = LMGetTime();
- tempPB.dirInfo.ioDrDirID = theFile->parID;
- PBSetCatInfoSync(&tempPB);
- }
- }
- }
- – Craig Marciniak
- TemplarDev@aol.com
-
- Hot Tip for Hot Keys
- One of the things I appreciate in applications is the ability to select
- buttons with keystrokes (the keyboard shortcut is know as a hotkey).
- The following code example adds hotkey functionality to alert dialogs
- and can be easily added to modal dialogs. The next time you use an alert,
- add AlertKeyProc to the function and you will have instant hotkey
- functionality. Simply change
- CautionAlert(ALERT_ID, NIL)
- to
- CautionAlert(SAVE_ALERT_ID, AlertKeyProc)
-
- #include <Dialogs.h>
- #define kEnterKey 3
- #define kReturnKey 13
- #define kEscapeKey 27
-
- pascal Boolean AlertKeyProc(DialogPtr theDialog, EventRecord *e, short *itemHit)
- {
- char theChar;
- short num, i, iType;
- Handle iHandle;
- Rect iRect;
- Str255 iText;
- long finalTicks;
-
- switch( e->what )
- {
- case keyDown:
- case autoKey:
- theChar = (e->message & charCodeMask);
- if(theChar == kReturnKey || theChar == kEnterKey)
- {
- *itemHit = 1;
- return( TRUE );
- }
- else if(theChar == kEscapeKey)
- {
- *itemHit = 2;
- return( TRUE );
- }
- else
- {
- num = CountDITL( theDialog );
- for(i=0; i<num; i++)
- {
- GetDItem(theDialog, i, &iType, &iHandle, &iRect);
- if(iType == ctrlItem + btnCtrl)
- {// If the button is a push button
- GetCTitle((ControlHandle )iHandle, iText);
- if(theChar == iText[1] ||
- theChar == tolower(iText[1]))
- {
- *itemHit = i;
- HiliteControl((ControlHandle )iHandle, 1);
- return( TRUE );
- }
- }
- }
- }
- break;
- }
- return( FALSE );
- }
-